﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:control="clr-namespace:for7raid.Control"
        xmlns:local="clr-namespace:for7raid.vkPlayer"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ListBox.xaml"/>
                <ResourceDictionary Source="Button.xaml"/>
                <ResourceDictionary Source="SearchButton.xaml"/>
                <ResourceDictionary Source="CustomWindowChrome.xaml"/>
                <ResourceDictionary Source="Slider.xaml"/>
                <ResourceDictionary Source="HyperlinkComboBox.xaml"/>
                <ResourceDictionary Source="MediaItemDataTemplate.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    <DataTemplate x:Key="FullViewTemplate">
        <Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext}">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>


            <control:AutoCompleteTextBox Margin="3" Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}" AutoSuggestionList="{Binding SearchHistory}" Grid.Column="1">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="KeyUp">
                        <control:CommandAction Command="{Binding SearchBoxKeyUpCommand}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </control:AutoCompleteTextBox>


            <StackPanel Grid.Row="1" HorizontalAlignment="Right" Margin="5,0" Orientation="Horizontal" Grid.Column="1">
                <TextBlock Text="Слушать  "/>
                <TextBlock>
                <Hyperlink Command="{Binding SearchMyCommand}">
                    <TextBlock Text="свои"/>
                </Hyperlink>
            </TextBlock>
                <TextBlock Text=" | "/>
                <ComboBox Style="{StaticResource HyperlinkComboBox}" Text="у друга" 
                          ItemsSource="{Binding Friends}"
                          local:PlayerViewModel.UpdateCommand="local:PlayerViewModel.UpdateFriendCommand">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                            <TextBlock.ToolTip>
                                <Image MaxHeight="64" MaxWidth="64" Source="{Binding Photo}"/>
                            </TextBlock.ToolTip>
                           <Hyperlink Command="local:PlayerViewModel.SearchByFriendCommand" CommandParameter="{Binding}">
                                <TextBlock>
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0} {1}">
                                            <Binding Path="FirstName"/>
                                            <Binding Path="LastName"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </Hyperlink>
                        </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock Text=" | "/>
                <ComboBox Style="{StaticResource HyperlinkComboBox}" Text="в группе" ItemsSource="{Binding Groups}"
                           local:PlayerViewModel.UpdateCommand="local:PlayerViewModel.UpdateGroupCommand">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock MaxWidth="300" TextTrimming="CharacterEllipsis">
                           <Hyperlink Command="local:PlayerViewModel.SearchByGroupCommand" CommandParameter="{Binding}">
                                <TextBlock Text="{Binding Name}"/>
                            </Hyperlink>
                        </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock Text=" | "/>
                <TextBlock>
                <Hyperlink Command="{Binding RandomCommand}">
                    <TextBlock Text="случайные"/>
                </Hyperlink>
            </TextBlock>
            </StackPanel>

            <TabControl Grid.Row="2" Grid.Column="1" Margin="3" HorizontalAlignment="Stretch" DataContext="{Binding}"
                        ItemsSource="{Binding PlayLists}" SelectedItem="{Binding CurrentPlayList}" HorizontalContentAlignment="Stretch">
                <TabControl.ItemTemplate>
                    <DataTemplate>

                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Image Source="../Icons/button-play.png" MaxHeight="14" HorizontalAlignment="Left" VerticalAlignment="Center"
                                   DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window}}">
                                <Image.ToolTip>
                                    <TextBlock>
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="{}{0} - {1}">
                                                <Binding Path="CurrentItem.Artist"/>
                                                <Binding Path="CurrentItem.Title"/>
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </Image.ToolTip>
                                <Image.Resources>
                                    <Style TargetType="Image">
                                        <Style.Triggers>
                                            <DataTrigger Value="false">
                                                <DataTrigger.Binding>
                                                    <MultiBinding>
                                                        <Binding Path="DataContext.CurrentItem" RelativeSource="{RelativeSource AncestorType=Window}"/>
                                                        <Binding Path="DataContext.Items" RelativeSource="{RelativeSource AncestorType=TabItem}"/>
                                                        <Binding Path="DataContext.Position" RelativeSource="{RelativeSource AncestorType=Window}"/>
                                                        <MultiBinding.Converter>
                                                            <local:CurrentItemInTheListConverter/>
                                                        </MultiBinding.Converter>
                                                    </MultiBinding>
                                                </DataTrigger.Binding>
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Resources>
                            </Image>
                            <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding SearchText}" ToolTip="{Binding SearchText}" TextTrimming="CharacterEllipsis" HorizontalAlignment="Center">
                                  <!--<TextBlock.ContextMenu>
                                  <ContextMenu>
                                  <MenuItem Header="Группировать по альбомам" IsCheckable="True" 
                                   IsChecked="{Binding Path=(local:PlayerViewModel.IsGrouppedByAlbum)}"/>
                                  </ContextMenu>
                                  </TextBlock.ContextMenu>-->
                            </TextBlock>
                        </Grid>

                    </DataTemplate>
                </TabControl.ItemTemplate>
                <TabControl.ContentTemplate>
                    <DataTemplate>

                        <ListBox Name="itemslist"
                                DataContext="{Binding}"
                             ItemsSource="{Binding Items}" SelectedItem="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}" 
                             SelectionMode="Extended"
                             IsSynchronizedWithCurrentItem="True"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                             HorizontalContentAlignment="Stretch"
                                 VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard"
                             ItemTemplate="{StaticResource MediaItemDataTemplate}">
                            <ListBox.Resources>
                                <SolidColorBrush 
                                    x:Key="{x:Static SystemColors.HighlightBrushKey}"  
                                    Color="Transparent" />
                            </ListBox.Resources>
                            <!--<ListBox.GroupStyle>
                                <GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/>
                                <GroupStyle>
                                    <GroupStyle.HeaderTemplate>
                                        <DataTemplate>
                                             <TextBlock>
                                                           <TextBlock.Text>
                                                                <MultiBinding>
                                                                <Binding Path="Name"/>
                                                                <Binding Path="DataContext.Albums" RelativeSource="{RelativeSource AncestorType=ListBox}"/>
                                                                <MultiBinding.Converter>
                                                                    <local:AlbumIdToTitleConverter/>
                                                                </MultiBinding.Converter>
                                                            </MultiBinding>
                                                           </TextBlock.Text>
                                                    </TextBlock>
                                        </DataTemplate>
                                    </GroupStyle.HeaderTemplate>
                                </GroupStyle>
                            </ListBox.GroupStyle>-->
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseDoubleClick">
                                    <control:CommandAction Command="{Binding DataContext.PlaySelectedCommand, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </i:EventTrigger>
                                <control:KeyUpEventTrigger Key="Enter">
                                    <control:CommandAction Command="{Binding DataContext.PlaySelectedCommand, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="Q">
                                    <control:CommandAction Command="{Binding DataContext.QueueCommand, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="S">
                                    <control:CommandAction Command="{Binding DataContext.StopAfterThisCommand, RelativeSource={RelativeSource AncestorType=Window}}" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="Insert">
                                    <control:CommandAction Command="local:PlayerViewModel.AddToMeCommand" CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="Delete">
                                    <control:CommandAction Command="local:PlayerViewModel.RemoveFromListCommand" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="Delete" Modifier="Shift">
                                    <control:CommandAction Command="local:PlayerViewModel.DeleteCommand" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="C" Modifier="Control">
                                    <control:CommandAction Command="local:PlayerViewModel.CopyCommand" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="F3">
                                    <control:CommandAction Command="local:PlayerViewModel.SearchByArtistCommand" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="F2">
                                    <control:CommandAction Command="local:PlayerViewModel.EditCommand" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="D" Modifier="Control">
                                    <control:CommandAction Command="local:PlayerViewModel.DownloadCommand" 
                                                           CommandParameter="{Binding DataContext.SelectedItem, RelativeSource={RelativeSource AncestorType=Window}}"/>
                                </control:KeyUpEventTrigger>
                                <control:KeyUpEventTrigger Key="F5">
                                    <control:CommandAction Command="local:PlayerViewModel.UpdateListCommand" />
                                </control:KeyUpEventTrigger>
                            </i:Interaction.Triggers>

                            <i:Interaction.Behaviors>
                                <control:ScrollIntoViewBehavior/>
                            </i:Interaction.Behaviors>


                            <ListBox.ItemContainerStyle>

                                <Style TargetType="ListBoxItem">


                                    <Setter Property="ToolTip">
                                        <Setter.Value>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                     <MultiBinding StringFormat="{}{0} - {1}">
                                                        <Binding Path="Artist"/>
                                                        <Binding Path="Title"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </Setter.Value>
                                    </Setter>


                                </Style>
                            </ListBox.ItemContainerStyle>

                        </ListBox>

                    </DataTemplate>
                </TabControl.ContentTemplate>

            </TabControl>



            <!--Прогресс скачивания текущей песни-->
            <ProgressBar  Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="10,0"
                          HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="10"
                          Maximum="100" 
                          Value="{Binding Path=CurrentItemDownloadProgress, Mode=OneWay}">
                <ProgressBar.Resources>
                    <Style TargetType="ProgressBar">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=CurrentItemDownloadProgress, Mode=OneWay}" Value="0">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=CurrentItemDownloadProgress, Mode=OneWay}" Value="100">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ProgressBar.Resources>
            </ProgressBar>
            <Slider Maximum="{Binding Duration.TotalMilliseconds, Mode=OneWay}" Value="{Binding Position}" 
                    Grid.Row="3" IsTabStop="False" Margin="10,0" Orientation="Horizontal" Grid.Column="1"
                    SmallChange="0.001" LargeChange="5000"
                    control:SliderPreviewBehavior.ContentStyle="{StaticResource PreviewStyle}">
                <Slider.ToolTip>
                    <TextBlock>
                        <TextBlock.Text>
                            <Binding Path="Position">
                                <Binding.Converter>
                                    <local:TimeConverter/>
                                </Binding.Converter>
                            </Binding>
                        </TextBlock.Text>
                    </TextBlock>
                </Slider.ToolTip>
                <i:Interaction.Behaviors>
                    <control:SliderPreviewBehavior/>
                    <control:SliderMouseBehavior/>
                </i:Interaction.Behaviors>
            </Slider>

            <StackPanel Grid.Row="4" Margin="3" Orientation="Horizontal" HorizontalAlignment="Center" Grid.Column="1">
                <StackPanel Margin="0,0,5,0">
                    <ToggleButton IsChecked="{Binding IsShuffle}" MaxHeight="20" VerticalAlignment="Top" ToolTip="Произвольный режим">
                        <Image Source="..\Icons\button-shuffle.png"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </ToggleButton>

                    <ToggleButton IsChecked="{Binding IsRepeat}"  MaxHeight="20" VerticalAlignment="Bottom" ToolTip="Повторять текущую запись">
                        <Image Source="..\Icons\button-rotate-cw.png"   HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </ToggleButton>
                </StackPanel>


                <Button Command="MediaCommands.PreviousTrack" CommandTarget="{Binding}">
                    <Image Source="../Icons/button-rew.png" MaxHeight="32"/>
                </Button>
                <Button  Command="MediaCommands.Stop" CommandTarget="{Binding}">
                    <Image Source="../Icons/button-stop.png" MaxHeight="32"/>
                    <Button.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Остановить после текущего" IsCheckable="True" IsChecked="{Binding IsStopAfterCurrent}"/>
                        </ContextMenu>
                    </Button.ContextMenu>
                </Button>
                <Button  Command="MediaCommands.Play" CommandTarget="{Binding}">
                    <Image Source="../Icons/button-play.png" MaxHeight="32"/>
                </Button>
                <Button  Command="MediaCommands.Pause" CommandTarget="{Binding}">
                    <Image Source="../Icons/button-pause.png" MaxHeight="32"/>
                </Button>
                <Button  Command="MediaCommands.NextTrack" CommandTarget="{Binding}">
                    <Image Source="../Icons/button-ff.png" MaxHeight="32"/>
                </Button>
                <Button Style="{StaticResource VolumeButton}" Margin="5" MaxHeight="24">

                </Button>
            </StackPanel>

            <Border Background="AliceBlue" BorderBrush="Gray" BorderThickness="1" CornerRadius="5" Width="300" Grid.RowSpan="5" Margin="3" Visibility="Collapsed">
                <Border.Style>
                    <Style TargetType="{x:Type Border}">
                        <Setter Property="Visibility" Value="Visible"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsShowLyrics}" Value="false">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <TextBlock Text="{Binding CurrentItem.Text}"/>
            </Border>


            <!--Строка состояния-->
            <ItemsControl  Grid.Row="5" Margin="3,5" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Grid.Column="1" ItemsSource="{Binding StatusText}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Name="textBox" Text="{Binding}" TextTrimming="CharacterEllipsis" ToolTip="{Binding}">
                            <TextBlock.Background>
                                <SolidColorBrush x:Name="TextBlockBrush" Color="Tan" />
                            </TextBlock.Background>
                        </TextBlock>
                        <DataTemplate.Triggers>
                            <EventTrigger RoutedEvent="FrameworkElement.Loaded" SourceName="textBox">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="TextBlockBrush"
                                                        Storyboard.TargetProperty="Color" To="Transparent" 
                                                        Duration="0:0:3.0" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>

                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
    </DataTemplate>
</ResourceDictionary>